package com.more.offer.algorithm.leetcode.lcode01;

import java.util.HashMap;
import java.util.Map;

/**
 * Date: 2020-03-15 12:40
 * Author: pinoc
 * Desc:
 */
public class Solution_1 {
	public static int[] twoSum(int[] nums, int target) {
		Map<Integer,Integer> map = new HashMap();
		for (int i=0; i<nums.length;i++) {
			if(map.get(nums[i])!=null) {
				continue;
			}
			map.put(nums[i],i); //值：索引
		}

		for (int i=0; i<nums.length;i++) {
			int k = target - nums[i];

			if(map.containsKey(k) && map.get(k)!=i) {
				return new int[]{i,map.get(k)};
			}
		}
		return null;
	}

	public static void main(String[] args) {
		int[] nums = {1,3,5,7,32,11,9,9};
		int target = 10;
		int a [] = twoSum(nums,target);
		for (int i: a) {
			System.out.println(i);
		}
	}
}
